<%@ page language="java" contentType="text/html;charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="java.util.*"%>
<%@ page import="com.hz.util.*"%>
<%@page import="com.hz.model.Service" %>
<%@page import="com.hz.model.User" %>
<%@page import="com.hz.control.UserControl" %>
<%@page import="com.hz.control.ActivityControl"%>
<%@page import="com.hz.model.Activity"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<HTML> 
<HEAD> 
<TITLE> New Document </TITLE> 
<link rel="stylesheet" type="text/css" href="../../../css/active.css"/>
<link type="text/css" href="../../../resources/components/jquery-ui/css/smoothness/jquery-ui-1.8.16.custom.css" rel="stylesheet" />	
<script type="text/javascript" src="../../../resources/components/jquery-ui/js/jquery-1.6.2.min.js"></script>
<script type="text/javascript" src="../../../resources/components/jquery-ui/js/jquery-ui-1.8.16.custom.min.js"></script>
<script type="text/javascript">
	$(document).ready(function() {
		$('#formdiv').hide();
		$('#add_student').click(function() {
			$('#formdiv').slideToggle();
		});
			$('#submit_btn').click(function() {
			$.ajax( {
				type : "get",
				cache : false,
				dataType : "json",
				url : "listadd.jsp",
				data : {
					id:$('#id').val(),
					service:$('#service').val(),
					activity:$('#activity').val(),
					behavior:$('#behavior').val(),
					duty:$('#duty').val()
				},
				success : function(data) {
					if (data.status == 1) {
						window.location.reload();
					} else {
						alert("加入失败!确认信息填写完整以及非重复提交个人服务项目");
					}
				}
			});
		})
		$('[name=delete]').click(function() {
						$.ajax( {
							type : "get",
							cache : false,
							url : "listdelete.jsp",
							dataType : "json",
							data : {
								id : $(this).prev().val()
							},
							success : function(data) {
								if (data.status == 1) {
									window.location.reload();
								} else {
									alert("删除失败！");
						}
					}
				});
		})
	})
</script>
<script>
	$(function() {
		$( "#tags" ).autocomplete({
			source: function( request, response ) {
				$.ajax({
					url: "autocomplete.jsp?term="+request.term,
					dataType: "json",
					
					success: function( data ) {
					
						response( $.map( data, function( item ) {
							return {
							
								td: item.name,
								value: item.name+"  "+item.stunum,
								id:item.id
								
							}
						}));
					}
				});
			},
			select: function( event, ui ) {
				document.getElementById('id').value = ui.item.id;
				
			}
		});
	});
	</script>
	<script type="text/javascript">
	$(function(){
		$(".odd tbody tr:odd").css('background','#eee');
	});
</script>
</HEAD> 

<BODY> 
  <h1 class='title'>添加活动人员</h1>
<form>
<table class='add odd'>
<thead>
<tr>
		<th>姓名</th>
		<th>学号</th>
		<th>活动</th>
		<th>服务项目</th>
		<th>服务时长</th>
		<th>表现</th>
		<th>操作</th>
</tr>
</thead>
<tbody>
<%
    //注意此页面的id不要轻易修改
	request.setCharacterEncoding("UTF-8");
	 ArrayList<Service> slist = new ArrayList<Service>();
     Service s = new Service();
     float service = 0;
     if(session.getAttribute("addservice")!=null){
        service = (Float)session.getAttribute("addservice");
     }
	if(session.getAttribute("servelist")==null){
	out.print(" ");}else{
	slist = (ArrayList)session.getAttribute("servelist");
	System.out.println(slist.size());
	for(int i=0;i<slist.size();i++){
	     s = (Service)slist.get(i);
	     User user = new User();
	     user = UserControl.getUserInformation(s.getUserid());
%>  

	
		<tr>
		<td><%=user.getRealname()%></td>
		<td><%=user.getStuNum()%></td>
		
		<td><%=ActivityControl.getActivityInformation(s.getActId()).getActName()%></td>
		<td><%=s.getDuty()%></td>
		<td><%=s.getServicesHours() %></td>
		<td><%if(s.getBehavior()==1)out.print("优秀");
		      if(s.getBehavior()==2)out.print("良好");
		      if(s.getBehavior()==3)out.print("一般");
		    %></td>
		<td>
		<input type="hidden" id="index" name="index"  value="<%=i%>"/>
		<input type="button" value="移除" name="delete" ></td>
		</tr>
	<%
		}}
	%> 
		
   	</tbody>
   </table>
   <p class='para'>
   <input type="button" id="add_student" value="添加"/>&nbsp;&nbsp;&nbsp;
   <input type="button"  value="提交" onclick="window.location.href='addService_do.jsp'" /></p>
			</form>
			
		<div id="formdiv">
			<form action="#" method="post">
			<table class='add'>
			<tr>
						<td colspan="2">参与活动<select id="activity" name="activity">
						<option value="">-请选择-</option>
						<%

				               Collection c = ActivityControl.getActivities();
				               Iterator iterator = c.iterator();
				               while (iterator.hasNext()) {
					                 Activity pro = (Activity) iterator.next();
					                 %>
			            <option value="<%=pro.getId() %>" <%if(session.getAttribute("addactivity")!=null&&(Integer)(session.getAttribute("addactivity"))==pro.getId())out.println("selected='selected'");%>><%=ActivityControl.getActivityInformation(pro.getId()).getActName()+""+pro.getStartTime().substring(0,10) %></option>
			            <%}
				            
			            %>
		                    </select>
		                </td></tr>
		                <tr><td>姓名
			<input type="text" id="tags" name="new_name" value="" />
			</td>
		                <td>服务项目<input type="text" name="duty" id="duty"></td>
						</tr>
		                <tr>	<td>
			服务时长
			<input type="text" id="service" name="service" value="<%=service %>"  onkeyup="value=value.replace(/[^\d{1,}\.\d{1,}|\d{1,}]/g,'')" / >
			</td>
		                <td>表现<select name="behavior" id="behavior">
		                <option value="1">优秀</option>
		                <option value="2">良好</option>
		                <option value="3">一般</option>
		                </select></td>
		                </tr>  <tr><td colspan='4'>
		                <input type="hidden" id="id" name="id" value=""  />
		                <input type="button" id="submit_btn" value="添加" />
		                </td></tr>
			</table>
			
			</form>
		</div>
			

</BODY> 
</HTML> 
